Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/share/public_paths/embed/[...id].tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert } from "antd";6import Link from "next/link";7import PathContents from "components/share/path-contents";8import PathActions from "components/share/path-actions";9import Loading from "components/share/loading";10import getPublicPathInfo from "lib/share/get-public-path-info";11import useCounter from "lib/share/counter";12import { Embed } from "components/share/layout";13import withCustomize from "lib/with-customize";14import { Customize } from "lib/share/customize";15import { getTitle } from "lib/share/util";16import { Customize as CustomizeType } from "@cocalc/database/settings/customize";17import { PathContents as PathContentsInterface } from "lib/share/get-contents";1819interface Props {20id: string;21project_id: string;22path: string;23relativePath: string;24contents: PathContentsInterface;25error: string;26customize: CustomizeType;27}2829export default function PublicPath(props: Props) {30const { id, project_id, path, relativePath, contents, error, customize } =31props;32useCounter(id);33if (id == null) return <Loading style={{ fontSize: "30px" }} />;3435return (36<Customize value={customize}>37<Embed title={getTitle({ path, relativePath })}>38<div39style={{40backgroundColor: "white",41display: "inline-block",42padding: "0 5px",43margin: "5px",44width: "100%",45}}46>47<PathActions48id={id}49path={path}50project_id={project_id}51relativePath={relativePath}52isDir={!!contents?.isdir}53exclude={new Set(["embed"])}54/>55</div>56{contents != null && (57<PathContents58id={id}59relativePath={relativePath}60path={path}61{...contents}62/>63)}64{error != null && (65<Alert66showIcon67type="error"68style={{ maxWidth: "700px", margin: "30px auto" }}69message="Error loading file"70description={71<div>72There was a problem loading "{relativePath}" in{" "}73<Link href={`/share/public_paths/${id}`}>{path}.</Link>74<br />75<br />76{error}77</div>78}79/>80)}81</Embed>82</Customize>83);84}8586export async function getServerSideProps(context) {87const id = context.params.id[0];88const relativePath = context.params.id.slice(1).join("/");89try {90const props = await getPublicPathInfo({91id,92relativePath,93req: context.req,94});95return await withCustomize({96context,97props: { ...props, layout: "embed" },98});99} catch (_err) {100console.log(_err);101return { notFound: true };102}103}104105106